package servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Contact;
import persistence.ContactDAO;
import persistence.PersistenceUtil;

/**
 * Servlet implementation class DetailContact
 */
public class DetailContact extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DetailContact() {
        super();
        PersistenceUtil.init();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		long cid = Long.parseLong(request.getParameter("cid"));
		System.out.println("DetailContact get request cid : "+cid);
		ContactDAO cDAO = new ContactDAO();
		Contact c = cDAO.findById(cid);
		request.setAttribute("contact", c);
		request.getRequestDispatcher("jsp/detailContact.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}

}
